﻿using AVCUMPlatform.DAL.Interface;
using AVCUMPlatform.Entities;
using AVCUMPlatform.HelperLibrary;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AVCUMPlatform.DAL.Implement
{
    public class MessageDAL : BasDAL<Messagequeues>, IMessageDAL
    {
        public List<Messagequeues> GetAll()
        {
            string sql = SQLHelper.BuildSelectSQL<Messagequeues>(null, null);
            return DapperHelper.GetModelList<Messagequeues>(sql);
        }

        public bool Add(Messagequeues t)
        {
            return BaseAdd(t);
        }

        public bool Delete(List<int> ids)
        {
            return BaseDelete(ids);
        }

        public bool Update(Messagequeues t)
        {
            return BaseUpdate(t);
        }

        public Messagequeues Get(int id)
        {
            return BaseGet(id);
        }

        public List<Messagequeues> GetList(out int count, int page = 1, int per_page = 20)
        {
            string sql = SQLHelper.BuildSelectSQL<Messagequeues>(null,null,null,false, "createtime",true);
            sql = sql.Substring(0, sql.Length - 1);

            string countsql = "select count(*) from (" + sql + ") as temp;";
            count = DapperHelper.GetValue<int>(countsql);

            sql += " limit @sindex,@eindex;";
            return DapperHelper.GetModelList<Messagequeues>(sql, new { sindex = (page * per_page) - per_page, eindex = per_page });
        }

        public int AddReturnAutoId(Messagequeues t)
        {
            return BaseAddReturnAutoId(t);
        }
    }
}
